package com.zuqiuzhandui.liveing.common;

import android.text.TextUtils;

import com.zuqiuzhandui.R;

/**
 * Created by yq on 2016-10-12.
 */

public class CheckParameter {


    public static class CheckParameterHolder{
        private final static  CheckParameter INSTANCE=new CheckParameter();
    }
    public static CheckParameter getInstance(){
        return CheckParameterHolder.INSTANCE;
    }

    public String checkPhone(String mobile){
        String nowMobile=mobile.trim();
        if (TextUtils.isEmpty(mobile)) {
            return getStrForResoursId(R.string.error_empty_phone);
        }
        else if (mobile.length()!=11)
            return getStrForResoursId(R.string.error_phone);
        return null;
    }

    public String checkCode(String code){
        String nowCode=code.trim();
        if (TextUtils.isEmpty(nowCode)) {
            return getStrForResoursId(R.string.error_empty_code);
        }
        else if (nowCode.length()!=4)
            return getStrForResoursId(R.string.error_code);
        return null;
    }

    public String checkLogin(String mobile,String code){
        String errorMobile= checkPhone(mobile);
        String errorCode = checkCode(code);
        if (errorMobile!=null)
            return errorMobile;
        else if (errorCode!=null)
            return errorCode;
        return null;
    }


    public String checkTeamAndSchedule(int teamIndex, int scheduleIndex) {
        if (teamIndex==-1) {
            return getStrForResoursId(R.string.error_empty_team);
        }
        else if (scheduleIndex==-1)
            return getStrForResoursId(R.string.error_empty_schedule);
        return null;
    }



    private String getStrForResoursId(int resoursId){
     return   MyApplication.getInstance().getResources().getString(resoursId);
    }

}
